
// panel object
local PANEL = { };


/*------------------------------------
	initialize the visualization
------------------------------------*/
function PANEL:Init( )

	// create the container
	self.Container = vgui.Create( "MXVisualization_Container", self );

end


/*------------------------------------
	layout the visualization area
------------------------------------*/
function PANEL:PerformLayout( )

	// clamp the maximum size
	local w = math.min( self:GetWide(), 425 );
	
	// calculate height depending on aspect ratio
	local h = w * 0.75;
	
	// calculate the max height
	local mh = self:GetTall() * 0.95;
	
	// make sure its not too tall
	if ( h > mh ) then
	
		// adjust the width & height
		h = mh;
		w = h * 1.33;
	
	end
	
	// size & position the container
	self.Container:SetSize( w, h );
	self.Container:SetPos( ( self:GetWide() * 0.5 ) - ( w * 0.5 ), ( self:GetTall() * 0.5 ) - ( h * 0.5 ) );

end


/*------------------------------------
	mouse pressed event
------------------------------------*/
function PANEL:OnMousePressed( mcode )

	// only for right mouse button
	if ( mcode != MOUSE_RIGHT ) then
	
		// nada to do
		return;
		
	end

	// default last pressed
	self.LastPressed = self.LastPressed or 0;
	
	// make sure it isn't happening too fast
	if ( MXCurTime() - self.LastPressed < 1 ) then
	
		// bai
		return;
		
	end
	
	// open menu
	MuseX.SettingsMenu();

end


/*------------------------------------
	visualization background
------------------------------------*/
function PANEL:Paint( )

	// don't draw shit
	return true;

end


/*------------------------------------
	open visualization settings
------------------------------------*/
function PANEL:OpenSettings( )

	// get the visualization name
	local vis = MuseX.GetSetting( "visualization" );
	
	// get visualization table
	local tbl = MuseX.VisualizationList[ vis ];
	
	// make sure there are settings to configure
	if ( !tbl || !tbl.Settings ) then
	
		// nothing to configure, leave!
		return;
		
	end

	// check if the settings dialog has been opened
	if ( !self.SettingsDialog || !self.SettingsDialog:IsValid() ) then
	
		// if not, create it
		self.SettingsDialog = vgui.Create( "MXVisualizationSettings" );
		
		// not visible
		self.SettingsDialog:SetVisible( false );
		
		// set position
		self.SettingsDialog:Center();
		
	end
	
	// open
	self.SettingsDialog:Open();

end



// define
derma.DefineControl( "MXVisualization", "", PANEL, "DPanel" );


// panel object
local PANEL = { };


/*------------------------------------
	initialize visualization
	container area
------------------------------------*/
function PANEL:Init( )

	// waffles
	
end


/*------------------------------------
	mouse pressed event
------------------------------------*/
function PANEL:OnMousePressed( mcode )

	// pass to parent
	self:GetParent():OnMousePressed( mcode );

end


/*------------------------------------
	draw visualization container
------------------------------------*/
function PANEL:Paint( )

	// get the width and height
	local w = self:GetWide();
	local h = self:GetTall();
	
	// draw a black background
	draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 0 , 255 ) );
	
	// let the visualization render
	MuseX.RenderVisualization( self );
	
	// override painting
	return true;

end

// define
derma.DefineControl( "MXVisualization_Container", "", PANEL, "DPanel" );
